<?php if (!defined('THINK_PATH')) exit(); /*a:1:{s:84:"C:\phpstudy\WWW\tea\public/../application/operation_management\view\range\range.html";i:1533199756;}*/ ?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">

    <title>权限管理</title>

    <meta name="keywords" content="">
    <meta name="description" content="">

    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->

    <link rel="shortcut icon" href="favicon.ico"> <link href="/static/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/static/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="/static/css/animate.css" rel="stylesheet">
    <link href="/static/css/style.css?v=4.1.0" rel="stylesheet">
    <style type="text/css">
        th,td{
            text-align: center;
            width: 10%;
        }
    </style>
</head>
<body>
<form action="<?php echo url('newuser'); ?>" method="post">
    <div style="width:60%;margin: 20px auto;">
        <span style="margin:20px 10px 0px; ">账号</span><input name="user">
        <span style="margin:20px 10px 0px;">密码</span><input name="password">
        <span style="margin:20px 10px 0px;">权限</span>
        <select name="grade" style="height: 23px">
            <option value="2">二级</option>
            <option value="3">三级</option>
        </select>
        <button style="margin:20px 0px 0px 20px; ">创建</button>
    </div>
</form>

<div class="ibox-content" style="width:60%;margin: 0 auto;text-align: center;">
    <table class="table table-bordered">
        <thead>
            <tr>
                <th>户名账号</th>
                <th>昵称</th>
                <th>用户密码</th>
                <th>用户权限</th>
                <th>上次登录时间</th>
                <th>修改</th>
                <th>删除</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach($users as $user): ?>
            <tr>
                <td><?php echo $user['user']; ?></td>
                <td><input nid=<?php echo $user['id']; ?> name="nickname" value="<?php echo $user['nickname']; ?>" style="border:none;text-align: center;"></td>

                <td><input uid=<?php echo $user['id']; ?> name="password" value="<?php echo $user['password']; ?>" style="border:none;text-align: center;"></td>
                <td>
                    <select name="grade" uid='<?php echo $user['id']; ?>' class="grade">
                            <option value="2" <?php if($user['grade']==2): ?>selected='selected'<?php endif; ?>>二级</option>
                            <option value="3" <?php if($user['grade']==3): ?>selected='selected'<?php endif; ?>>三级</option>
                    </select>
                </td>
                <?php if(($user['time'])): ?>
                    <td><?php echo $user['time']; ?></td>
                <?php else: ?>
                    <td>新账号</td>
                <?php endif; ?>
                <td>
                     <button class="modify" uid="<?php echo $user['id']; ?>">修改</button>
                </td>
                <td>
                     <button class="del" uid="<?php echo $user['id']; ?>">删除</button>
                </td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>

</div>
<!-- 全局js -->
<script src="/static/js/jquery.min.js?v=2.1.4"></script>
<script src="/static/js/bootstrap.min.js?v=3.3.6"></script>
<script type="text/javascript">
    //修改
    $('.modify').click(function(){
        var url = "<?php echo url('modify'); ?>";
        var id = $(this).attr('uid');
        var password = $("input[uid="+id+"]").val();
        var grade = $("select[uid="+id+"]").val();
        var nickname = $("input[nid="+id+"]").val();
        var data = {
            id:id,
            password:password,
            grade:grade,
            nickname:nickname
        }
        $.post(url, data, function(data){
            if(data==1){
                alert("修改成功");
            }else{
                alert("修改失败");
            }
        })
    })

    //删除
    $('.del').click(function(){
        var url = "<?php echo url('userdel'); ?>";
        var id = $(this).attr('uid');
        var data = {
            id:id
        }
        $.post(url, data, function(data){
            if(data==1){
                alert("删除成功");
            }else{
                alert("删除失败");
            }
        })
    })

</script>



</body>
</html>